package jdbc;

import java.sql.*;

public class JDBCDemo8 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection();) {
            LoginUserInfo loginUserInfo = InputUtil.getInputObject(new LoginUserInfo(), "欢迎登录宝贝~~");
            String sql = "SELECT id,username,password,nickname,age FROM userinfo WHERE username = ? AND password = ?";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, loginUserInfo.getUsername());
            preparedStatement.setString(2, loginUserInfo.getPassword());
            ResultSet resultSet = preparedStatement.executeQuery();
            if (resultSet.next()) {
                String nickname = resultSet.getString("nickname");
                System.out.println("欢迎回来，" + nickname + "宝贝~！");
            } else {
                System.out.println("登陆失败");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
